﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace JiaBoPrint
{
    public partial class 诺贝达评审会打印 : Form
    {
        private IntPtr Gp_IntPtr;                   //驱动打印句柄
        private libUsbContorl.UsbOperation NewUsb = new libUsbContorl.UsbOperation();
        public 诺贝达评审会打印()
        {
            InitializeComponent();
        }
        private void 诺贝达评审会打印_Load(object sender, EventArgs e)
        {
            //绑定品名下拉框
            multiComboBox1.CheckedListBox.Items.Add("全部");
            string sqlpm = "select distinct b.productname from [results] a left join[products] b on a.dm = b.duanma";
            DataTable dtpm = DBHelper.ExecuteDataTable(sqlpm);
            for (int i = 0; i < dtpm.Rows.Count; i++)
            {
                multiComboBox1.CheckedListBox.Items.Add(dtpm.Rows[i]["productname"].ToString());
            }
        }

        private void comboBox1_DropDown(object sender, EventArgs e)
        {
            comboBox1.Items.Clear();
            List<String> combox = multiComboBox1.SelectedItems1;
            if (combox != null)
            {
                if (combox.Count > 0)
                {
                    for (int i = 0; i < combox.Count; i++)
                    {
                        string pm = combox[i].ToString();
                        string sqlpm = "";
                        if (pm == "全部")
                        {
                            sqlpm = @"select distinct b.kh from [results] a left join [products] b on a.dm = b.duanma";
                        }
                        else
                        {
                            sqlpm = @"select distinct b.kh from [results] a left join [products] b on a.dm = b.duanma
                                           where b.productname='{0}'";
                            sqlpm = string.Format(sqlpm, pm);
                        }

                        DataTable dtpm = DBHelper.ExecuteDataTable(sqlpm);
                        for (int j = 0; j < dtpm.Rows.Count; j++)
                        {
                            comboBox1.Items.Add(dtpm.Rows[j]["kh"].ToString());
                        }
                    }
                }
                else
                {
                    MessageBox.Show("请先选择品名");
                }
            }
            else
            {
                MessageBox.Show("请先选择品名");
            }
        }

        private void btn_print_Click(object sender, EventArgs e)
        {
            string dm = comboBox1.Text.ToString();
            //如果单个短码没值就根据品名打
            if (dm == "")
            {
                List<String> combox = multiComboBox1.SelectedItems1;
                if (combox != null)
                {
                    for (int i = 0; i < combox.Count; i++)
                    {
                        string sqlpm = "";
                        string pm = combox[i].ToString();
                        if (pm == "全部")
                        {
                            sqlpm = @"select distinct a.dm from [results] a left join [products] b on a.dm = b.duanma";

                        }
                        else
                        {
                            sqlpm = @"select distinct a.dm from [results] a left join [products] b on a.dm = b.duanma
                                      where b.productname='{0}' order by a.dm";
                            sqlpm = string.Format(sqlpm, pm);
                        }
                        DataTable dtpm = DBHelper.ExecuteDataTable(sqlpm);
                        for (int j = 0; j < dtpm.Rows.Count; j++)
                        {
                            string sqldm = @"exec zdy_getInfoByDm '{0}'";
                            sqldm = string.Format(sqldm, dtpm.Rows[j]["dm"].ToString());
                            DataTable dtdm = DBHelper.ExecuteDataTable(sqldm);

                            if (dtdm.Rows.Count > 0)
                            {
                                NewUsb.FindUSBPrinter();
                                for (int k = 0; k < NewUsb.USBPortCount; k++)
                                {
                                    if (NewUsb.LinkUSB(k))
                                    {
                                        SendData2USB("SIZE 50 mm,80 mm\r\n");//设置标签大小，单位mm.具体参数请用尺子量一下
                                        SendData2USB("GAP 6 mm,0 mm\r\n");//设置两个标签之间的间隙，单位mm.具体参数请用尺子量一下
                                        SendData2USB("CLS\r\n");//清空缓冲区
                                        SendData2USB("DENSITY 7\r\n");//打印浓度
                                        SendData2USB("REFERENCE 0,0\r\n");
                                        SendData2USB("TEXT 2,10,\"TSS20.BF2\",0,1,1,\"短码\"\r\n");
                                        SendData2USB("TEXT 60,10,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["dm"].ToString() + "\"\r\n");
                                        SendData2USB("TEXT 160,10,\"TSS20.BF2\",0,1,1,\"品类\"\r\n");
                                        SendData2USB("TEXT 200,10,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["productname"].ToString() + "\"\r\n");
                                        SendData2USB("TEXT 2,40,\"TSS20.BF2\",0,1,1,\"系列\"\r\n");
                                        SendData2USB("TEXT 60,40,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["xilie"].ToString() + "\"\r\n");
                                        SendData2USB("TEXT 160,40,\"TSS20.BF2\",0,1,1,\"长码\"\r\n");
                                        SendData2USB("TEXT 200,40,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["kh"].ToString() + "\"\r\n");

                                        SendData2USB("TEXT 2,90,\"TSS16.BF2\",0,1,1,\"用户名\"\r\n");
                                        SendData2USB("TEXT 70,90,\"TSS16.BF2\",0,1,1,\"价格\"\r\n");
                                        SendData2USB("TEXT 110,90,\"TSS16.BF2\",0,1,1,\"陈列\"\r\n");
                                        SendData2USB("TEXT 150,90,\"TSS16.BF2\",0,1,1,\"加色\"\r\n");
                                        SendData2USB("TEXT 190,90,\"TSS16.BF2\",0,1,1,\"意见\"\r\n");
                                        SendData2USB("TEXT 330,90,\"TSS16.BF2\",0,1,1,\"评分\"\r\n");
                                        int gd = 90;
                                        for (int x = 0; x < dtdm.Rows.Count; x++)
                                        {
                                            gd = gd + 30;
                                            SendData2USB("TEXT 2," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["username"].ToString() + "\"\r\n");
                                            SendData2USB("TEXT 70," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["price"].ToString() + "\"\r\n");
                                            SendData2USB("TEXT 110," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["iscl"].ToString() + "\"\r\n");
                                            SendData2USB("TEXT 150," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["addcolor"].ToString() + "\"\r\n");
                                            SendData2USB("TEXT 190," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["yj"].ToString() + "\"\r\n");
                                            SendData2USB("TEXT 330," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["pf"].ToString() + "\"\r\n");

                                        }
                                        //                 string sqldmpjf = @"select round(dbo.ClearZero(sum(cast(pf as decimal(8,2)))/count(CASE WHEN pf IS NOT NULL THEN 1 END)),1) pjf,
                                        //                                 round(dbo.ClearZero(sum(cast((case when pf_two is null then pf else pf_two end) as decimal(8,2)))
                                        ///count(case when pf_two is null then pf else pf_two end)),1) pjf2
                                        //                                 from results where dm='{0}'";
                                        string sqldmpjf = @"exec [zdy_getInfoByDm_pjf] '{0}'";
                                        sqldmpjf = string.Format(sqldmpjf, dtpm.Rows[j]["dm"].ToString());
                                        DataTable dtdmpjf = DBHelper.ExecuteDataTable(sqldmpjf);
                                        decimal pjf = Convert.ToDecimal(dtdmpjf.Rows[0]["pjf"].ToString());
                                        gd = gd + 30;
                                        SendData2USB("TEXT 330," + gd + ",\"TSS20.BF2\",0,1,1,\"" + pjf + "\"\r\n");

                                        SendData2USB("PRINT 1\r\n");
                                        NewUsb.CloseUSBPort();
                                    }
                                    else
                                    {
                                        MessageBox.Show("请确定是否连接上打印机");
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show("短码不存在");
                            }
                        }
                    }
                }
            }
            else
            {
                string sqldm = @"exec zdy_getInfoByDm '{0}'";
                sqldm = string.Format(sqldm, dm);
                DataTable dtdm = DBHelper.ExecuteDataTable(sqldm);
                if (dtdm.Rows.Count > 0)
                {
                    NewUsb.FindUSBPrinter();
                    for (int k = 0; k < NewUsb.USBPortCount; k++)
                    {
                        if (NewUsb.LinkUSB(k))
                        {
                            SendData2USB("SIZE 50 mm,80 mm\r\n");//设置标签大小，单位mm.具体参数请用尺子量一下
                            SendData2USB("GAP 6 mm,0 mm\r\n");//设置两个标签之间的间隙，单位mm.具体参数请用尺子量一下
                            SendData2USB("CLS\r\n");//清空缓冲区
                            SendData2USB("DENSITY 7\r\n");//打印浓度
                            SendData2USB("REFERENCE 0,0\r\n");
                            SendData2USB("TEXT 10,10,\"TSS20.BF2\",0,1,1,\"短码\"\r\n");
                            SendData2USB("TEXT 60,10,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["dm"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 160,10,\"TSS20.BF2\",0,1,1,\"品类\"\r\n");
                            SendData2USB("TEXT 200,10,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["productname"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 10,40,\"TSS20.BF2\",0,1,1,\"系列\"\r\n");
                            SendData2USB("TEXT 60,40,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["xilie"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 160,40,\"TSS20.BF2\",0,1,1,\"长码\"\r\n");
                            SendData2USB("TEXT 200,40,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["kh"].ToString() + "\"\r\n");

                            SendData2USB("TEXT 2,90,\"TSS16.BF2\",0,1,1,\"用户名\"\r\n");
                            SendData2USB("TEXT 70,90,\"TSS16.BF2\",0,1,1,\"价格\"\r\n");
                            SendData2USB("TEXT 110,90,\"TSS16.BF2\",0,1,1,\"陈列\"\r\n");
                            SendData2USB("TEXT 150,90,\"TSS16.BF2\",0,1,1,\"加色\"\r\n");
                            SendData2USB("TEXT 190,90,\"TSS16.BF2\",0,1,1,\"意见\"\r\n");
                            SendData2USB("TEXT 330,90,\"TSS16.BF2\",0,1,1,\"评分\"\r\n");
                            int gd = 90;
                            for (int x = 0; x < dtdm.Rows.Count; x++)
                            {
                                gd = gd + 30;
                                SendData2USB("TEXT 2," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["username"].ToString() + "\"\r\n");
                                SendData2USB("TEXT 70," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["price"].ToString() + "\"\r\n");
                                SendData2USB("TEXT 110," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["iscl"].ToString() + "\"\r\n");
                                SendData2USB("TEXT 150," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["addcolor"].ToString() + "\"\r\n");
                                SendData2USB("TEXT 190," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["yj"].ToString() + "\"\r\n");
                                SendData2USB("TEXT 330," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["pf"].ToString() + "\"\r\n");

                            }
                            //                 string sqldmpjf = @"select round(dbo.ClearZero(sum(cast(pf as decimal(8,2)))/count(CASE WHEN pf IS NOT NULL THEN 1 END)),1) pjf,
                            //                                 round(dbo.ClearZero(sum(cast((case when pf_two is null then pf else pf_two end) as decimal(8,2)))
                            ///count(case when pf_two is null then pf else pf_two end)),1) pjf2
                            //                                 from results where dm='{0}'";
                            string sqldmpjf = @"exec [zdy_getInfoByDm_pjf] '{0}'";
                            sqldmpjf = string.Format(sqldmpjf, dm);
                            DataTable dtdmpjf = DBHelper.ExecuteDataTable(sqldmpjf);
                            decimal pjf = Convert.ToDecimal(dtdmpjf.Rows[0]["pjf"].ToString());
                            gd = gd + 30;
                            SendData2USB("TEXT 330," + gd + ",\"TSS20.BF2\",0,1,1,\"" + pjf + "\"\r\n");

                            SendData2USB("PRINT 1\r\n");
                            NewUsb.CloseUSBPort();
                        }
                        else
                        {
                            MessageBox.Show("请确定是否连接上打印机");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("短码不存在");
                }
            }
        }

        private void SendData2USB(byte[] str)
        {
            NewUsb.SendData2USB(str, str.Length);
        }
        private void SendData2USB(string str)
        {
            byte[] by_SendData = System.Text.Encoding.GetEncoding(54936).GetBytes(str);
            SendData2USB(by_SendData);
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)//如果输入的是回车键  
            {
                string dm = textBox1.Text.ToString();
                string sqldm = @"exec zdy_getInfoByDm '{0}'";
                sqldm = string.Format(sqldm, dm);
                DataTable dtdm = DBHelper.ExecuteDataTable(sqldm);
                if (dtdm.Rows.Count > 0)
                {
                    NewUsb.FindUSBPrinter();
                    for (int k = 0; k < NewUsb.USBPortCount; k++)
                    {
                        if (NewUsb.LinkUSB(k))
                        {
                            SendData2USB("SIZE 50 mm,80 mm\r\n");//设置标签大小，单位mm.具体参数请用尺子量一下
                            SendData2USB("GAP 6 mm,0 mm\r\n");//设置两个标签之间的间隙，单位mm.具体参数请用尺子量一下
                            SendData2USB("CLS\r\n");//清空缓冲区
                            SendData2USB("DENSITY 7\r\n");//打印浓度
                            SendData2USB("REFERENCE 0,0\r\n");
                            SendData2USB("TEXT 2,10,\"TSS20.BF2\",0,1,1,\"短码\"\r\n");
                            SendData2USB("TEXT 60,10,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["dm"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 160,10,\"TSS20.BF2\",0,1,1,\"品类\"\r\n");
                            SendData2USB("TEXT 230,10,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["productname"].ToString() + "\"\r\n");
                            SendData2USB("TEXT 2,40,\"TSS20.BF2\",0,1,1,\"系列\"\r\n");
                            SendData2USB("TEXT 60,40,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["xilie"].ToString() + "\"\r\n");
                            //SendData2USB("TEXT 160,40,\"TSS20.BF2\",0,1,1,\"长码\"\r\n");
                            //SendData2USB("TEXT 200,40,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["kh"].ToString() + "\"\r\n");

                            SendData2USB("TEXT 2,90,\"TSS16.BF2\",0,1,1,\"用户名\"\r\n");
                            SendData2USB("TEXT 70,90,\"TSS16.BF2\",0,1,1,\"价格\"\r\n");
                            SendData2USB("TEXT 110,90,\"TSS16.BF2\",0,1,1,\"陈列\"\r\n");
                            SendData2USB("TEXT 150,90,\"TSS16.BF2\",0,1,1,\"加色\"\r\n");
                            SendData2USB("TEXT 190,90,\"TSS16.BF2\",0,1,1,\"意见\"\r\n");
                            SendData2USB("TEXT 300,90,\"TSS16.BF2\",0,1,1,\"评分\"\r\n");
                            int gd = 90;
                            for (int x = 0; x < dtdm.Rows.Count; x++)
                            {
                                gd = gd + 30;
                                SendData2USB("TEXT 2," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["username"].ToString() + "\"\r\n");
                                SendData2USB("TEXT 70," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["price"].ToString() + "\"\r\n");
                                SendData2USB("TEXT 110," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["iscl"].ToString() + "\"\r\n");
                                SendData2USB("TEXT 150," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["addcolor"].ToString() + "\"\r\n");
                                SendData2USB("TEXT 190," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["yj"].ToString() + "\"\r\n");
                                SendData2USB("TEXT 300," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["pf"].ToString() + "\"\r\n");

                            }


                            string sqldmpjf = @"exec [zdy_getInfoByDm_pjf] '{0}'";
                            sqldmpjf = string.Format(sqldmpjf, dm);
                            DataTable dtdmpjf = DBHelper.ExecuteDataTable(sqldmpjf);

                            for (int j = 0; j < dtdmpjf.Rows.Count; j++)
                            {
                                gd = gd + 30;
                                SendData2USB("TEXT 10," + gd + ",\"TSS24.BF2\",0,1,1,\"" + dtdmpjf.Rows[j]["lx"].ToString() + "\"\r\n");
                                SendData2USB("TEXT 200," + gd + ",\"TSS24.BF2\",0,1,1,\"" + dtdmpjf.Rows[j]["sz"].ToString() + "\"\r\n");
                            }

                            SendData2USB("PRINT 1\r\n");
                            NewUsb.CloseUSBPort();

                            textBox1.Text = "";
                        }
                        else
                        {
                            MessageBox.Show("请确定是否连接上打印机");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("短码不存在");
                }
            }
        }
        //要或不要版本
        //private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        //{
        //    if (e.KeyChar == 13)//如果输入的是回车键  
        //    {
        //        string dm = textBox1.Text.ToString();
        //        string sqldm = @"exec zdy_getInfoByDm '{0}'";
        //        sqldm = string.Format(sqldm, dm);
        //        DataTable dtdm = DBHelper.ExecuteDataTable(sqldm);
        //        if (dtdm.Rows.Count > 0)
        //        {
        //            NewUsb.FindUSBPrinter();
        //            for (int k = 0; k < NewUsb.USBPortCount; k++)
        //            {
        //                if (NewUsb.LinkUSB(k))
        //                {
        //                    SendData2USB("SIZE 50 mm,80 mm\r\n");//设置标签大小，单位mm.具体参数请用尺子量一下
        //                    SendData2USB("GAP 6 mm,0 mm\r\n");//设置两个标签之间的间隙，单位mm.具体参数请用尺子量一下
        //                    SendData2USB("CLS\r\n");//清空缓冲区
        //                    SendData2USB("DENSITY 7\r\n");//打印浓度
        //                    SendData2USB("REFERENCE 0,0\r\n");
        //                    SendData2USB("TEXT 2,10,\"TSS20.BF2\",0,1,1,\"短码\"\r\n");
        //                    SendData2USB("TEXT 60,10,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["dm"].ToString() + "\"\r\n");
        //                    SendData2USB("TEXT 160,10,\"TSS20.BF2\",0,1,1,\"品类\"\r\n");
        //                    SendData2USB("TEXT 230,10,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["productname"].ToString() + "\"\r\n");
        //                    SendData2USB("TEXT 2,40,\"TSS20.BF2\",0,1,1,\"系列\"\r\n");
        //                    SendData2USB("TEXT 60,40,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["xilie"].ToString() + "\"\r\n");
        //                    //SendData2USB("TEXT 160,40,\"TSS20.BF2\",0,1,1,\"长码\"\r\n");
        //                    //SendData2USB("TEXT 200,40,\"TSS20.BF2\",0,1,1,\"" + dtdm.Rows[0]["kh"].ToString() + "\"\r\n");

        //                    SendData2USB("TEXT 2,90,\"TSS16.BF2\",0,1,1,\"用户名\"\r\n");
        //                    SendData2USB("TEXT 70,90,\"TSS16.BF2\",0,1,1,\"价格\"\r\n");
        //                    SendData2USB("TEXT 110,90,\"TSS16.BF2\",0,1,1,\"陈列\"\r\n");
        //                    SendData2USB("TEXT 150,90,\"TSS16.BF2\",0,1,1,\"加色\"\r\n");
        //                    SendData2USB("TEXT 190,90,\"TSS16.BF2\",0,1,1,\"意见\"\r\n");
        //                    SendData2USB("TEXT 300,90,\"TSS16.BF2\",0,1,1,\"要或不要\"\r\n");
        //                    int gd = 90;
        //                    for (int x = 0; x < dtdm.Rows.Count; x++)
        //                    {
        //                        gd = gd + 30;
        //                        SendData2USB("TEXT 2," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["username"].ToString() + "\"\r\n");
        //                        SendData2USB("TEXT 70," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["price"].ToString() + "\"\r\n");
        //                        SendData2USB("TEXT 110," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["iscl"].ToString() + "\"\r\n");
        //                        SendData2USB("TEXT 150," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["addcolor"].ToString() + "\"\r\n");
        //                        SendData2USB("TEXT 190," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["yj"].ToString() + "\"\r\n");
        //                        SendData2USB("TEXT 300," + gd + ",\"TSS16.BF2\",0,1,1,\"" + dtdm.Rows[x]["isbl"].ToString() + "\"\r\n");

        //                    }
        //                    //                 string sqldmpjf = @"select round(dbo.ClearZero(sum(cast(pf as decimal(8,2)))/count(CASE WHEN pf IS NOT NULL THEN 1 END)),1) pjf,
        //                    //                                 round(dbo.ClearZero(sum(cast((case when pf_two is null then pf else pf_two end) as decimal(8,2)))
        //                    ///count(case when pf_two is null then pf else pf_two end)),1) pjf2
        //                    //                                 from results where dm='{0}'";
        //                    string sqldmpjf = @"exec [zdy_getInfoByDm_pjf] '{0}'";
        //                    sqldmpjf = string.Format(sqldmpjf, dm);
        //                    DataTable dtdmpjf = DBHelper.ExecuteDataTable(sqldmpjf);
        //                    decimal xycount = Convert.ToDecimal(dtdmpjf.Rows[0]["xycount"].ToString());
        //                    decimal bxycount = Convert.ToDecimal(dtdmpjf.Rows[0]["bxycount"].ToString());
        //                    string xybfb = dtdmpjf.Rows[0]["xybfb"].ToString();
        //                    string bxybfb = dtdmpjf.Rows[0]["bxybfb"].ToString();
        //                    gd = gd + 20;
        //                    SendData2USB("TEXT 2," + gd + ",\"TSS20.BF2\",0,1,1,\"-----------------------------------\"\r\n");
        //                    gd = gd + 30;
        //                    SendData2USB("TEXT 2," + gd + ",\"TSS20.BF2\",0,1,1,\"需要人数：\"\r\n");
        //                    SendData2USB("TEXT 110," + gd + ",\"TSS20.BF2\",0,1,1,\"" + xycount + "\"\r\n");
        //                    SendData2USB("TEXT 200," + gd + ",\"TSS20.BF2\",0,1,1,\"不需要人数：\"\r\n");
        //                    SendData2USB("TEXT 330," + gd + ",\"TSS20.BF2\",0,1,1,\"" + bxycount + "\"\r\n");
        //                    gd = gd + 30;
        //                    SendData2USB("TEXT 2," + gd + ",\"TSS20.BF2\",0,1,1,\"需要占比：\"\r\n");
        //                    SendData2USB("TEXT 110," + gd + ",\"TSS20.BF2\",0,1,1,\"" + xybfb + "\"\r\n");
        //                    SendData2USB("TEXT 200," + gd + ",\"TSS20.BF2\",0,1,1,\"不需要占比：\"\r\n");
        //                    SendData2USB("TEXT 330," + gd + ",\"TSS20.BF2\",0,1,1,\"" + bxybfb + "\"\r\n");

        //                    SendData2USB("PRINT 1\r\n");
        //                    NewUsb.CloseUSBPort();

        //                    textBox1.Text = "";
        //                }
        //                else
        //                {
        //                    MessageBox.Show("请确定是否连接上打印机");
        //                }
        //            }
        //        }
        //        else
        //        {
        //            MessageBox.Show("短码不存在");
        //        }
        //    }
        //}



        //private void button1_Click(object sender, EventArgs e)
        //{
        //    NewUsb.FindUSBPrinter();
        //    for (int i = 0; i < NewUsb.USBPortCount; i++)
        //    {
        //        if (NewUsb.LinkUSB(i))
        //        {
        //            SendData2USB("SIZE 50 mm,80 mm\r\n");//设置标签大小，单位mm.具体参数请用尺子量一下
        //            SendData2USB("GAP 6 mm,0 mm\r\n");//设置两个标签之间的间隙，单位mm.具体参数请用尺子量一下
        //            SendData2USB("CLS\r\n");//清空缓冲区
        //            SendData2USB("DENSITY 7\r\n");//打印浓度
        //            SendData2USB("REFERENCE 0,0\r\n");
        //            //1:x方向起始点坐标 2:y方向起始点坐标a 3:字体 4：旋转角度 5：x_反相区域宽度，单位dot
        //            //6:y_反相区域高度，单位dot 7:内容 *font 字体名称* 1 8×12 dot 英数字体*2 12×20 dot 英数字体
        //            //*3 16×24 dot 英数字体*4 24×32 dot 英数字体*5 32×48 dot 英数字体*6 14×19 dot 英数字体OCR-B
        //            //*7 21×27 dot 英数字体OCR-B*8 14×25 dot 英数字体OCR-A*9 9×17 dot 英数字体*10 12×24 dot 英数字体
        //            //*TSS16.BF2 简体中文16×16（GB 码） *TSS20.BF2 简体中文20×20（GB 码）*TST24.BF2 繁体中文24×24（大五码）
        //            //*TSS24.BF2 简体中文24×24（GB 码）*K 韩文24×24Font（KS 码）*TSS32.BF2 简体中文32×32（GB 码）
        //           //*rotation 文字旋转角度（顺时针方向） 0， 90， 180， 270
        //            SendData2USB("TEXT 330,10,\"TSS20.BF2\",90,1,1,\"短码\"\r\n");
        //            SendData2USB("TEXT 330,70,\"TSS20.BF2\",90,1,1,\"品名\"\r\n");
        //            SendData2USB("TEXT 330,130,\"TSS20.BF2\",90,1,1,\"用户名\"\r\n");
        //            SendData2USB("TEXT 330,195,\"TSS20.BF2\",90,1,1,\"风格\"\r\n");
        //            SendData2USB("TEXT 330,240,\"TSS20.BF2\",90,1,1,\"价格\"\r\n");
        //            SendData2USB("TEXT 330,300,\"TSS20.BF2\",90,1,1,\"有无陈列\"\r\n");
        //            SendData2USB("TEXT 330,380,\"TSS20.BF2\",90,1,1,\"是否加色\"\r\n");
        //            SendData2USB("TEXT 330,460,\"TSS20.BF2\",90,1,1,\"加色\"\r\n");
        //            SendData2USB("TEXT 330,510,\"TSS20.BF2\",90,1,1,\"意见\"\r\n");
        //            SendData2USB("TEXT 330,590,\"TSS20.BF2\",90,1,1,\"评分\"\r\n");

        //            //StreamReader strReadFile = new StreamReader(@"./10.bmp");
        //            //byte[] byteReadData = new byte[strReadFile.BaseStream.Length];
        //            //strReadFile.BaseStream.Read(byteReadData, 0, byteReadData.Length);
        //            //strReadFile.Close();
        //            //SendData2USB("DOWNLOAD \"10.bmp\",4094,");
        //            //SendData2USB(byteReadData);//bmp数据
        //            //SendData2USB("PUTBMP 14,110,\"10.bmp\"\r\n");
        //            SendData2USB("PRINT 1\r\n");

        //            NewUsb.CloseUSBPort();
        //        }
        //    }
        //}
    }
}
